package com.hama.iotrust.ws.ext;

import java.io.Serializable;

import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.soap.SOAPFaultException;

public class APIServiceException extends Exception implements Serializable {

    private static final long serialVersionUID = 6216481208796638900L;
    private String            code;
    private String            message;

    public APIServiceException(String code, String message){
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Throwable getCause() {
        SOAPFault fault;
        try {
            fault = SOAPFactory.newInstance().createFault();
            fault.setFaultCode(code);
            fault.setFaultString(message);
            SOAPFaultException ex = new SOAPFaultException(fault);
            return ex;
        } catch (SOAPException e) {
            return super.getCause();
        }
    }
}
